package com.fr.chicken.manager.verifcode;

import java.util.concurrent.TimeUnit;

/**
 * 验证码
 * */
public final class VarcharCode {

    private final String verifyCode;

    private final long createTime;

    public VarcharCode(String verifyCode, long createTime){
        this.verifyCode = verifyCode;
        this.createTime = createTime;
    }


    /**
     * 验证码
     * */
    public String getVerifyCode() {
        return verifyCode;
    }

    /**
     * 验证码创建时间 单位毫秒
     * */
    public long getCreateTime() {
        return createTime;
    }

    /**
     * 检查验证码是否有效
     * */
    public boolean valid(long time, TimeUnit timeUnit){
        return timeUnit.toMillis(time) >= (System.currentTimeMillis() - createTime);
    }

}
